package controllers.listeners.lexicon;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import controllers.shared.GetInputLoop;

import models.LexiconModel;

import objects.LexiconList;
import views.ViewLexicon;

/* Adds a new syntactic category (e.g. "Masculine", "Noun", etc.) */
/* actionPerformed when you click on the "Adds Syntactic Category" button */
public class AddSyntacticListener implements ActionListener{
	
	ViewLexicon view;
	
	public void setView(ViewLexicon view) {
		this.view = view;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		String input = null;
		
		GetInputLoop.setInputDialog("Enter a new Syntactic Category:", "New Syntactic Category", JOptionPane.OK_CANCEL_OPTION);
		GetInputLoop.setErrorDialog("", "");
		input = GetInputLoop.getInput();
		
		if (input == null) {
			return;
		}
		
		view.addCategoryToChooser(input);
		LexiconList lexicon = new LexiconList();
		lexicon.setLabel(input);
		LexiconModel.getLexicon().addLexiconListItem(lexicon);
	}
	
}
